#include <iterator>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;

namespace Me{
    
template<class Iter>
class reverse_iterator:public iterator<typename iterator_traits<Iter>::iterator_category,
				       typename iterator_traits<Iter>::value_type,
				       typename iterator_traits<Iter>::difference_type,
				       typename iterator_traits<Iter>::pointer,
				       typename iterator_traits<Iter>::reference>{
protected:
    Iter current;
public:
    typedef Iter iterator_type;
    reverse_iterator():current(){}
    explicit reverse_iterator(Iter x):current(x){}
    template<class U> reverse_iterator(const reverse_iterator<U>&x):current(x.base()){}
    Iter base()const{return current;}
    reference operator*()const{Iter tmp = current; return *--tmp;}
    pointer operator->()const;
    reference operator[](difference_type n)const;

    reverse_iterator& operator++(){--current;return *this;}
    reverse_iterator operator++(int){iterator_type t = current; --current; return reverse_iterator<Iter>(t);}
    reverse_iterator& operator--(){++current;return *this;}
    reverse_iterator operator--(int){iterator_type t = current; ++current; return reverse_iterator<Iter>(t);}

    reverse_iterator operator+(difference_type n)const;
    reverse_iterator& operator+=(difference_type n);
    reverse_iterator operator-(difference_type n)const;
    reverse_iterator& operator-=(difference_type n);
};
}

int main()
{
    int i[] = {0, 1, 2, 3};
    vector<int> vi(i, i+4);
    copy(vi.begin(), vi.end(), ostream_iterator<int>(cout, " "));
    Me::reverse_iterator<vector<int>::iterator>  ri(vi.end());
    ++ri;++ri;
    ri++;
    cout << *ri << endl;
    
    list<int> li(i, i+4);
    Me::reverse_iterator<list<int>::iterator>  rli(li.end());    


}

    
    
